import axios from 'axios';

export default {
  async getStars() {
    //throw new Error("API demo error")
    // eslint-disable-next-line no-unreachable
    return (await axios.get("/api/collection/"))
      .data.results
      .map((x) => Object.assign(
        {},
        x.paper_content,
        {
          collection_id: x.id,
          id: x.paper
        },
      ))
  },
  async getFollowActivities() {
    let data = await axios.get("/api/follow/activities/")
    console.log(data)
    return data.data
  },
  async getHistory() {
    let _data = await axios.get("/api/history/skim/");
    let data = _data.data.results
    for(var i in data){
      var time = data[i].skim_time
      var date= new Date(time).toJSON()
      var creationTimeStr= new Date(+new Date(date) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
      data[i].skim_time = creationTimeStr;
    }
   return data
  },
  async getActivities() {
    let data = await this.getStars()
    return data
  },
  async addSubscription(topic){
    let data = {
      "topic": topic
    }
    data = await axios.post("/api/topic/", data)
    return data.data.results
  },
  async getSubscriptions() {
    let data = await axios.get("/api/topic/")
    console.log(data.data.results)
    return data.data.results
  },
  async removeSubscription(topic_id) {
    let data = await axios.delete("/api/topic/"+topic_id+"/")
    return data.data.results
  },
  async getFollows() {
    let data = await (await axios.get("/api/follow/")).data.results
    return data
  },
  async unstar(id) {
    return await axios.delete(`/api/collection/${id}/`)
  },
  async unfollow(id) {
    return await axios.delete(`/api/follow/${id}/`)
  },
  async get() {
    //throw new Error("API demo error")
    // eslint-disable-next-line no-unreachable
    return [
      {
        avatar: require('@/assets/images/avatars/1.png'),
        title: 'Brunch this weekend?',
        subtitle: `<span class="text--primary">Ali Connors</span> &mdash; I'll be in your neighborhood doing errands this weekend. Do you want to hang out?`,
      },
      {
        avatar: require('@/assets/images/avatars/1.png'),
        title: 'Summer BBQ <span class="grey--text text--lighten-1">4</span>',
        subtitle: `<span class="text--primary">to Alex, Scott, Jennifer</span> &mdash; Wish I could come, but I'm out of town this weekend.`,
      },
      {
        avatar: require('@/assets/images/avatars/1.png'),
        title: 'Oui oui',
        subtitle: '<span class="text--primary">Sandra Adams</span> &mdash; Do you have Paris recommendations? Have you ever been?',
      },
      {
        avatar: require('@/assets/images/avatars/1.png'),
        title: 'Birthday gift',
        subtitle: '<span class="text--primary">Trevor Hansen</span> &mdash; Have any ideas about what we should get Heidi for her birthday?',
      },
      {
        avatar: require('@/assets/images/avatars/1.png'),
        title: 'Recipe to try',
        subtitle: '<span class="text--primary">Britta Holt</span> &mdash; We should eat this: Grate, Squash, Corn, and tomatillo Tacos.',
      },
    ]
  }
}
